<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;
class UserController extends PublicController {

	
	public function regAction(){
		$Model=D('User');
		$data=I('post.');	
		
		if(!empty($data)){
			
			if($data['password'] != $data['password_a']){
				$this->success('两次密码不一致', U('index/index'));
				die();
			}
			$data['password']=md5($data['password']);
			
			$one=$Model->add($data);
			if($one>0){
				$this->success('注册成功', U('index/index'));
				}else{
					$this->success('注册失败', U('user/reg'));
					}
		
		}
		
		$this->view();
	
    }
	
	
	public function loginAction(){	
		
		$Model=D('User');
		$data=I('post.');	
		
		if(!empty($data)){
	
			$username=$data['username'];
			$password=$data['password']=md5($data['password']);
	
			$one=$Model->where(" username='$username' and password='$password' ")->find();
			if($one){
				session('user',$one);
				$this->success('登陆成功', U('index/index'));
				}else{
					$this->success('登陆失败', U('user/login'));
					}
		
		}
		
		$this->view();
	
    }
	
	
	public function logoutAction(){
		session('user',null); // 删除user
		$ss=session('user');
		if(empty($ss)){
			$this->success('退出成功', U('index/index'));
		}else{
			$this->success('退出失败', U('user/login'));
		}
		
		
	}
	
	
	
	

	
	
	
}